package com.ruoyi.order.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.order.domain.OrdCartItem;
import com.ruoyi.order.service.IOrdCartItemService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 购物车表Controller
 * 
 * @author wpf
 * @date 2023-05-19
 */
@RestController
@RequestMapping("/order/cart")
public class OrdCartItemController extends BaseController
{
    @Autowired
    private IOrdCartItemService ordCartItemService;

    /**
     * 查询购物车表列表
     */
    @PreAuthorize("@ss.hasPermi('order:cart:list')")
    @GetMapping("/list")
    public TableDataInfo list(OrdCartItem ordCartItem)
    {
        startPage();
        List<OrdCartItem> list = ordCartItemService.selectOrdCartItemList(ordCartItem);
        return getDataTable(list);
    }

    /**
     * 导出购物车表列表
     */
    @PreAuthorize("@ss.hasPermi('order:cart:export')")
    @Log(title = "购物车表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OrdCartItem ordCartItem)
    {
        List<OrdCartItem> list = ordCartItemService.selectOrdCartItemList(ordCartItem);
        ExcelUtil<OrdCartItem> util = new ExcelUtil<OrdCartItem>(OrdCartItem.class);
        util.exportExcel(response, list, "购物车表数据");
    }

    /**
     * 获取购物车表详细信息
     */
    @PreAuthorize("@ss.hasPermi('order:cart:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(ordCartItemService.selectOrdCartItemById(id));
    }

    /**
     * 新增购物车表
     */
    @PreAuthorize("@ss.hasPermi('order:cart:add')")
    @Log(title = "购物车表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrdCartItem ordCartItem)
    {
        return toAjax(ordCartItemService.insertOrdCartItem(ordCartItem));
    }

    /**
     * 修改购物车表
     */
    @PreAuthorize("@ss.hasPermi('order:cart:edit')")
    @Log(title = "购物车表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrdCartItem ordCartItem)
    {
        return toAjax(ordCartItemService.updateOrdCartItem(ordCartItem));
    }

    /**
     * 删除购物车表
     */
    @PreAuthorize("@ss.hasPermi('order:cart:remove')")
    @Log(title = "购物车表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ordCartItemService.deleteOrdCartItemByIds(ids));
    }
}
